<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Default Details</title>
	<link href="../../css/default.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="../../js/jsx.js"></script>
	<script type="text/javascript" src="../../js/jsml.js"></script>
	<script type="text/javascript" src="../../js/ui.js"></script>
	<script type="text/javascript" src="../../js/ris.js"></script>
	<script type="text/javascript" src="../../js/SR.js"></script>
	<script type="text/javascript" >
		var data = {};
		var errorProvider = new ErrorProvider();

		function onBodyLoad()
		{		   
			var startTime;
			var stopTime;
			var facility;
			var modality;

			if(Ris)
			{
				data = JSML.parse(Ris.getTag("Documentation")) || {};
			}

			data.comments = data.comments || [];
			initCommentsTable();
		}
		
		function initCommentsTable()
		{
			var commentsTable = Table.createTable($("commentsTable"), 
				{editInPlace: true, flow: true, checkBoxes: true },
				[
					{  label: "Comment",
						cellType: "textarea",
						getValue: function(item) { return item.comment; },
						setValue: function(item, value) { item.comment = value; },
						getError: function(item) { return null; }
					},
					{  label: "Author",
						cellType: "lookup",
						lookup: function(query) { return Ris.resolveStaffName(query); },
						getValue: function(item) { return item.staff; },
						setValue: function(item, value) { item.staff = value; },
						getError: function(item) { return null; }
					}
				]);
			
			commentsTable.errorProvider = errorProvider;
			commentsTable.bindItems(data.comments);               
		}
		
		function onAddComment()
		{
			data.comments.add( {} );
		}

		function onDeleteComment()
		{
			var checkedItems = $("commentsTable").getCheckedItems();
			if(checkedItems.length > 0)
			{
				if(confirm("Delete selected comments?"))
				{
						checkedItems.each(function(item) { data.comments.remove(item); });
						$("commentsCheckAllNone").checked = false;
				}
			}
			else
			{
				alert("Nothing selected");
			}
		}

		function onCommentCheckAllNone()
		{
			data.comments.each(function(item) { $("commentsTable").setItemCheckState(item, $("commentsCheckAllNone").checked); });
		}         

		//////////////////////////////////////////////////////////////////////////
		// RIS integration API
		function hasValidationErrors()
		{
			return errorProvider.hasErrors();
		}

		function showValidation(show)
		{
			errorProvider.setVisible(show);
		}

		function saveData()
		{
			Ris.setTag("Documentation", JSML.create(data, "data"));
		}
		//////////////////////////////////////////////////////////////////////////
	</script>
</head>
<body onload="javascript: onBodyLoad()">
	<form id="myForm">
		<p class="sectionheading">Comments</p>
		<div class="addDeleteButtons">
			<input type="button" value="Add" onclick="javascript: onAddComment()" />
			<input type="button" value="Delete" onclick="javascript: onDeleteComment()" />
		</div>
		<table id="commentsTable" border="1" width="100%">
			<tr>
				<td colspan="2"><input id="commentsCheckAllNone" type="checkbox" onclick="javascript:onCommentCheckAllNone()">Select All/None</input></td>
			</tr>
		</table>
	</form>
</body>
</html>
